<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <title>snsmi | Popular and highly playable games</title>
</head>

<link rel="stylesheet" href="./css/iconfont.css">
<link rel="stylesheet" href="./css/type.css">
<link rel="icon" href="./img/icon_game.png" type="image/x-icon">
<script>document.documentElement.style.fontSize = window.innerWidth / 640 * 100 + 'px'</script>
<script src="./js/rem_adaptive.js"></script>

<style>
  [v-cloak] {
    display: none;
  }
</style>

<body>
  <div id="app">
    <div class="main" v-cloak>

      <div class="header">
        <!-- pc_categories -->
        <a :href="`index.html?gameChannelId=${gameChannelId}${camp}${groupId}`" class="logo">
          <img src="./img/logo.png" alt="logo" width="125" height="60">
        </a>
        <a class="label" :href="handleTypeGames(cate.type)" v-for="cate in categories" :key="cate.type">
          <i class="label_icon">
            <img :src="cate.imgUrl" :alt="cate.type" width="30" height="30">
          </i>
          <span class="label_name">
            {{cate.name}}
          </span>
        </a>

        <!-- mobile_categories -->

        <div class="label-panel" :style="{display: labelHide ? 'block' : 'none'}">
          <a :href="`index.html?gameChannelId=${gameChannelId}${camp}${groupId}`" class="home">
            <img src="./img/logo.png" alt="logo" width="80">
          </a>
          <a class="label-container" :href="handleTypeGames(cate.type)" v-for="cate in categories" :key="cate.type">
            <i class="label_icon">
              <img :src="cate.imgUrl" :alt="cate.type">
            </i>
            <span class="label-name">{{cate.name}}</span>
          </a>
        </div>

        <!-- search -->
        <div class="search-head">
          <div class="menu-icon" @click="handleHideLabel" id="ShowMenu">
            <img src="./img/list.png" alt="menu" width="35">
          </div>
          <span>
            <input type="text" v-model="search" @focus="showSearchTable = true" @blur="showSearchTable = false" placeholder="Search games ..." spellcheck="false" dir="auto"
              autocomplete="off">
            <div class="search-data" :style="searchResultStyle">
              <div class="search-loading" v-if="!searchDone">
                <img src="./img/loading.gif" alt="loading" width="50">
              </div>
              <ul class="search-list" v-else-if="searchDone && searchResult.length > 0">
                <li class="result" v-for="item in searchResult" :key="item.gameId">
                  <a :href="handleDetail(item)">
                    <span class="game-name">{{item.gameName}}</span>
                  </a>
                </li>
              </ul>
              <div v-else class="search-loading">
                Search result is null
              </div>
            </div>
          </span>
        </div>


        <div class="search">
          <div class="search-menu">
            <input class="search_input" type="text" v-model="search" @focus="showSearchTable = true" @blur="showSearchTable = false" placeholder="Search Game...">
            <div class="search-btn" @click="handleToSearch">
              <img class="search-btn_img" src="./img/icon-search.png" alt="search_icon" width="20">
            </div>
            <div class="search-table" v-show="search.length > 0 && showSearchTable">
              <div class="search-loading" v-if="!searchDone">
                <img src="./img/loading.gif" alt="loading" width="50">
              </div>
              <ul v-else-if="searchDone && searchResult.length > 0">
                <li v-for="item in searchResult" :key="item.gameId">
                  <a :href="`${handleDetail(item)}&keyword=${item.gameName}`">
                    <span class="game-name">{{item.gameName}}</span>
                  </a>
                </li>
              </ul>
              <div v-else class="search-loading">
                Search result is null
              </div>
            </div>
          </div>
        </div>

      </div>



      <div class="posterBanner">
        <ins class="adsbygoogle" v-if="mobile" style="display:inline-block;width:320px;height:100px;"
          data-ad-client="ca-pub-1727029308377024" :data-ad-slot="accountInfo.mobile.type.top"></ins>

        <ins class="adsbygoogle" v-else style="display:block" data-ad-client="ca-pub-1727029308377024"
          :data-ad-slot="accountInfo.pc.type.top" data-ad-format="auto" data-full-width-responsive="true"></ins>

        <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
      </div>

      <div class="content">
        <a class="game scroll" :href="handleDetail(item)" v-for="item in searchResult" :key="item.gameId">
          <div class="game-pic">
            <img src="./img/picture.gif" class="pic lazyload fmt" :data-src="item.gameLogo" :alt="item.gameName">
          </div>
          <div class="name-box">
            <div class="name">{{item.gameName}}</div>
          </div>
        </a>
      </div>

      <div class="posterBanner">
        <ins class="adsbygoogle" v-if="mobile" style="display:inline-block;width:320px;height:100px;"
          data-ad-client="ca-pub-1727029308377024" :data-ad-slot="accountInfo.mobile.type.bottom"></ins>

        <ins class="adsbygoogle" v-else style="display:block" data-ad-client="ca-pub-1727029308377024"
          :data-ad-slot="accountInfo.pc.type.bottom" data-ad-format="auto" data-full-width-responsive="true"></ins>

        <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
      </div>
      <div class="footer">
        <div class="bottom-navbar">
          <a :href="handleToAboutContent('cookies')">
            Cookies
          </a>
          <a :href="handleToAboutContent('privacy')">
            Privacy Policy
          </a>
          <a href="mailto:linyating2000@gmail.com" target="_blank">Contact Us</a>
          <a :href="handleToAboutContent('company')">
            About Us
          </a>
        </div>
      </div>
    </div>
  </div>
</body>

<script src="./js/vue.min.js"></script>
<script src="./js/axios.min.js"></script>
<script src="./js/accountData.js"></script>
<script src="./js/afg.js"></script>
<script>
  function debounce(fn, delay) {
    let timer = null
    return function () {
      let that = this
      let args = arguments
      if (timer) {
        clearTimeout(timer)
      }
      timer = setTimeout(() => {
        fn.apply(that, args)
        clearTimeout(timer)
        timer = null
      }, delay)
    }
  }
</script>
<script>
  var vm = new Vue({
    el: '#app',
    data() {
      return {
        labelHide: false,

        shareStauts: false,

        gameChannelId: 4163,

        mobile: true,
        accountInfo: {},

        searchResult: [],
        search: '',
        searchDone: false,
        showSearchTable: false,
        categories: [
          {
            name: 'Hot Games',
            type: 'hot',
            imgUrl: './img/hot.png'
          },
          {
            name: 'Racing Games',
            type: 'racing',
            imgUrl: './img/racing-game.png'
          },
          {
            name: 'Shooter Games',
            type: 'shooter',
            imgUrl: './img/shooting-game.png'
          },
          {
            name: 'Action Games',
            type: 'action',
            imgUrl: './img/action-game.png'
          },
          {
            name: 'Casual Games',
            type: 'casual',
            imgUrl: './img/casual.png'
          },
          {
            name: 'Girls Games',
            type: 'girl',
            imgUrl: './img/girls.png'
          }
        ],

        camp: '',
        groupId: ''
      }
    },
    watch: {
      search(val) {
        this.searchGames(val)
      }
    },
    computed: {
      searchResultStyle() {
                return {
                    display: this.search.length === 0 || !this.showSearchTable ? 'none' : 'block'
                }
            },
    },
    methods: {
      handleDetail(item) {
        if (this.isScroll) { return }
        if (this.gameChannelId == 5972) {
          return `detail.html?gameChannelId=${this.gameChannelId}&gameId=${item.gameId}${this.camp}${this.groupId}`;
        } else {
          return `detail.html?gameChannelId=${this.gameChannelId}&gameId=${item.gameId}`;
        }
      },
      handleTypeGames(type) {
        if (this.gameChannelId == 5972) {
          return `type.html?gameChannelId=${this.gameChannelId}&type=${type}${this.camp}${this.groupId}`
        } else {
          return `type.html?gameChannelId=${this.gameChannelId}&type=${type}`;
        }
      },
      handleToAboutContent(type) {
        if (this.gameChannelId == 5972) {
          return `about_content.html?aboutContentType=${type}${this.camp}${this.groupId}`;
        } else {
          return `about_content.html?aboutContentType=${type}`;
        }
      },
      handleToSearch() {
        let url = ''
        if (this.gameChannelId == 5972) {
          url = `search.html?gameChannelId=${this.gameChannelId}&keyword=${this.search}${this.camp}${this.groupId}`
        } else {
          url = `search.html?gameChannelId=${this.gameChannelId}&keyword=${this.search}`
        }
        location.href = url
      },
      searchGames: debounce(function (searchWords = '3d') {
        this.searchDone = false
        axios({
          method: "post",
          url: "https://www.migame.vip/gamefront/gameList/search",
          data: {
            gameName: searchWords || '3d',
            isTop: -1,
            limit: 10,
            page: 1,
          }
        }).then(res => {
          this.searchResult = res.data.data
          this.searchDone = true
          this.$nextTick(() => {
            this.handleScroll()
          })
        })
      }, 500),
      handleHideLabel() {
        this.labelHide = !this.labelHide
      },
      getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
          var pair = vars[i].split("=");
          if (pair[0] == variable) { return pair[1]; }
        }
        return (false);
      },
      handleScroll() {
        var imgs = document.querySelectorAll('.pic')
        var game_items = document.querySelectorAll(".scroll")
        let scrolltop = document.documentElement.scrollTop || document.body.scrollTop;
        for (var i = 0; i < imgs.length; i++) {
          if ((window.innerHeight + scrolltop) > this.lazyload(game_items[i])) {
            (i => {
              setTimeout(() => {
                var temp = new Image()
                temp.src = imgs[i].getAttribute("data-src")
                temp.onload = () => {
                  imgs[i].src = imgs[i].getAttribute("data-src")
                }
              }, 100)
            })(i)
          }
        }
      },
      lazyload(e) {
        if (e != undefined) {
          return e.offsetTop
        }
      },
      getAdData() {
        var adjs = document.createElement('script')
        adjs.async = 'async'
        adjs.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1727029308377024'
        adjs.crossorigin = 'anonymous'
        adjs.setAttribute("data-ad-frequency-hint", "30s");
        adjs.setAttribute("data-ad-channel", this.accountInfo.adChannel);
        // adjs.setAttribute("data-adbreak-test","on");

        document.head.append(adjs)
      },
      loadGAScript() {
        var adjs = document.createElement('script')
        adjs.async = 'async'
        adjs.src = `https://www.googletagmanager.com/gtag/js?id=${this.accountInfo.ga}`

        document.body.append(adjs)

        if (this.accountInfo.ga2.length) {
          var adjs1 = document.createElement('script')
          adjs1.async = 'async'
          adjs1.src = `https://www.googletagmanager.com/gtag/js?id=${this.accountInfo.ga2}`

          document.body.append(adjs1)
        }
      },
    },
    created() {
      this.gameChannelId = this.getQueryVariable('gameChannelId') ? this.getQueryVariable('gameChannelId') : 4163
      this.accountInfo = googleAccount.hasOwnProperty(this.gameChannelId) ? googleAccount[this.gameChannelId] : googleAccount[4163]
      this.loadGAScript()

      if (this.gameChannelId == 5972) {
        const camp = this.getQueryVariable('camp')
        const groupId = this.getQueryVariable('groupId')
        this.camp = camp ? `&camp=${camp}` : ''
        this.groupId = groupId ? `&groupId=${groupId}` : ''
      }
    },
    mounted() {
      adPrepare()
      createScript()

      window.addEventListener("scroll", this.handleScroll, true)
      this.search = this.getQueryVariable('keyword') || ''

      this.searchGames(this.search)
      this.getAdData()

      if (window.screen.width > 768) {
        this.mobile = false
      }
    },
  })
</script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag() { dataLayer.push(arguments); }
  gtag('js', new Date());

  gtag('config', vm.accountInfo.ga);
  if (vm.accountInfo.ga2.length) {
    gtag('config', vm.accountInfo.ga2);
  }
</script>
<!-- Hotjar Tracking Code for my site -->
<script>
  if (vm.gameChannelId == 4163) {
    (function (h, o, t, j, a, r) {
      h.hj = h.hj || function () { (h.hj.q = h.hj.q || []).push(arguments) };
      h._hjSettings = { hjid: 3378431, hjsv: 6 };
      a = o.getElementsByTagName('head')[0];
      r = o.createElement('script'); r.async = 1;
      r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
      a.appendChild(r);
    })(window, document, 'https://static.hotjar.com/c/hotjar-', '.js?sv=');
  }
</script>
<script>
  var pattern = /^aswif/;
    window.addEventListener('blur', function() {
        if (pattern.test(document.activeElement.id)) {
          gtag('event', 'clickAd')
        }
    })
</script>
</html>